<?php 
    $this->Excel->openXls('files/templatePrm06kpi.xls');
    $this->Excel->ajoutDonneeParColEtLigne(1,2,date('d/m/Y'));
?>

<?php $i=0; $risks=$kpiData['risks']; ?>
<?php $r=$risks['N'];$r_n=$risks['N-1']  ?>
<h2><?php __('Risks PRM06_KPI')  ?> </h2>

    <table class="formstatus">
        <thead>
            <tr>    
                <th rowspan="2"><?php  __('Risks') ?></th>
                <th colspan="2"><?php  __('Number') ?></th>
                <th colspan="2"><?php  __('Percent') ?></th>
            </tr>
            <tr>
                <th><?php __('Year N: '.date('Y'))  ?></th>
                <?php $this->Excel->ajoutDonneeParColEtLigne(2,6,'Year N: '.date('Y')); ?>
                
                <th><?php __('Year N-1: '.(date('Y')-1))  ?></th>
                <?php $this->Excel->ajoutDonneeParColEtLigne(3,6,'Year N-1: '.(date('Y')-1)); ?>
                
                <th><?php __('Year N: '.date('Y'))  ?></th>
                <?php $this->Excel->ajoutDonneeParColEtLigne(4,6,'Year N: '.date('Y')); ?>
                
                <th><?php __('Year N-1: '.(date('Y')-1))  ?></th>
                <?php $this->Excel->ajoutDonneeParColEtLigne(5,6,'Year N-1: '.(date('Y')-1)); ?>
             
            </tr>
        </thead>
        <tbody>
            <?php $lg=7;  ?>
            <?php foreach($r as $key => $val):  ?>
            <?php (($i%2)>0)?$cl='impair':$cl='pair';  ?>
            <tr class="<?php echo $cl  ?>">
                <td><?php echo __($key,true)  ?></td>
                
                <?php $col=2;  ?>
                <?php foreach($val as $n => $v):  ?>
                    
                    <td><?php echo $v  ?></td>
                    <?php $this->Excel->ajoutDonneeParColEtLigne($col,$lg,$v); ?>
                    
                    <td><?php echo $r_n[$key." Year N-1"][$n];  ?></td>
                    <?php $this->Excel->ajoutDonneeParColEtLigne($col+1,$lg,$r_n[$key." Year N-1"][$n]); ?>
                    
                    <?php $col+=2;  ?>
                <?php endforeach;  ?>
            </tr>
            <?php $lg++;  ?>
            <?php $i++;endforeach;  ?>
        </tbody>
    </table>

<?php 


$this->Excel->saveAsXls('prm06kpi');
         $this->Excel->closeXls();
?>